

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Han Qiu">
  <meta name="keywords" content="">
  
    <meta name="description" content="一、基本使用1. 安装依赖1npm i -D webpack webpack-cli typescript ts-loader  2. webpack配置12345678910111213141516171819202122232425262728293031323334&#x2F;&#x2F; webpack.config.js&#x2F;&#x2F; 引入一个包const path &#x3D; require(&amp;#x27;path&amp;#x27">
<meta property="og:type" content="article">
<meta property="og:title" content="webpack打包ts">
<meta property="og:url" content="http://example.com/2022/02/24/webpack%E6%89%93%E5%8C%85ts/index.html">
<meta property="og:site_name" content="寒秋の博客">
<meta property="og:description" content="一、基本使用1. 安装依赖1npm i -D webpack webpack-cli typescript ts-loader  2. webpack配置12345678910111213141516171819202122232425262728293031323334&#x2F;&#x2F; webpack.config.js&#x2F;&#x2F; 引入一个包const path &#x3D; require(&amp;#x27;path&amp;#x27">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-02-24T08:10:27.000Z">
<meta property="article:modified_time" content="2022-02-24T08:16:01.453Z">
<meta property="article:author" content="Han Qiu">
<meta name="twitter:card" content="summary_large_image">
  
  
  <title>webpack打包ts - 寒秋の博客</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.14","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>blogs</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="webpack打包ts">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2022-02-24 16:10" pubdate>
        2022年2月24日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      3.4k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      28 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">webpack打包ts</h1>
            
            <div class="markdown-body">
              <h3 id="一、基本使用"><a href="#一、基本使用" class="headerlink" title="一、基本使用"></a>一、基本使用</h3><h4 id="1-安装依赖"><a href="#1-安装依赖" class="headerlink" title="1. 安装依赖"></a>1. 安装依赖</h4><figure class="highlight powershell"><table><tr><td class="gutter"><div class="code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><pre><code class="hljs powershell">npm i <span class="hljs-literal">-D</span> webpack webpack<span class="hljs-literal">-cli</span> typescript ts<span class="hljs-literal">-loader</span><br></code></pre></td></tr></table></figure>

<h4 id="2-webpack配置"><a href="#2-webpack配置" class="headerlink" title="2. webpack配置"></a>2. webpack配置</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// webpack.config.js</span><br><br><span class="hljs-comment">// 引入一个包</span><br><span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;path&#x27;</span>);<br><br><span class="hljs-comment">// webpack 中的所有配置信息都应该写在 module.exports 中</span><br><span class="hljs-built_in">module</span>.exports = &#123;<br><br>    <span class="hljs-comment">// 指定入口文件</span><br>    <span class="hljs-attr">entry</span>: <span class="hljs-string">&quot;./src/index.ts&quot;</span>,<br>    <br>    <span class="hljs-comment">// 指定打包文件所在的位置</span><br>    <span class="hljs-attr">output</span>: &#123;<br>        <span class="hljs-comment">// 打包文件目录</span><br>        <span class="hljs-attr">path</span>: path.resolve(__dirname, <span class="hljs-string">&#x27;dist&#x27;</span>),<br>        <span class="hljs-comment">// 打包文件名</span><br>        <span class="hljs-attr">filename</span>: <span class="hljs-string">&quot;bundle.js&quot;</span><br>    &#125;,<br>    <br>    <span class="hljs-comment">// 指定 webpack 打包时要使用的模块</span><br>    <span class="hljs-attr">module</span>: &#123;<br>        <span class="hljs-comment">// 指定要加载的规则</span><br>        <span class="hljs-attr">rules</span>: [<br>            &#123;<br>                <span class="hljs-comment">// 指定规则生效的文件</span><br>                <span class="hljs-attr">test</span>: <span class="hljs-regexp">/\.ts$/</span>,<br>                <span class="hljs-comment">// 要使用的 loader</span><br>                use: <span class="hljs-string">&#x27;ts-loader&#x27;</span>,<br>                <span class="hljs-comment">// 要排除的文件</span><br>                <span class="hljs-attr">exclude</span>: <span class="hljs-regexp">/node-modules/</span><br>            &#125;<br>        ]<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="3-ts编译配置"><a href="#3-ts编译配置" class="headerlink" title="3. ts编译配置"></a>3. ts编译配置</h4><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-comment">// tsconfig.json</span><br>&#123;<br>  <span class="hljs-attr">&quot;compilerOptions&quot;</span>: &#123;<br>    <span class="hljs-attr">&quot;module&quot;</span>: <span class="hljs-string">&quot;ES2015&quot;</span>,<br>    <span class="hljs-attr">&quot;target&quot;</span>: <span class="hljs-string">&quot;ES2015&quot;</span>,<br>    <span class="hljs-attr">&quot;strict&quot;</span>: <span class="hljs-literal">true</span><br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="4-打包命令配置"><a href="#4-打包命令配置" class="headerlink" title="4. 打包命令配置"></a>4. 打包命令配置</h4><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-comment">// package.json 文件的 scripts 配置中添加 &quot;build&quot;: &quot;webpack&quot;，打包时直接执行 npm run build 即可</span><br>&#123;<br>    <span class="hljs-attr">&quot;scripts&quot;</span>: &#123;<br>        <span class="hljs-attr">&quot;build&quot;</span>: <span class="hljs-string">&quot;webpack&quot;</span><br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>执行 npm run build 打包 ts 文件</li>
</ul>
<h3 id="二、进阶使用"><a href="#二、进阶使用" class="headerlink" title="二、进阶使用"></a>二、进阶使用</h3><h4 id="1-html-webpack-plugin"><a href="#1-html-webpack-plugin" class="headerlink" title="1. html-webpack-plugin"></a>1. html-webpack-plugin</h4><ul>
<li>作用：自动生成成 html 并引用相关资源（css、js…）</li>
<li>安装：<code>npm i -D html-webpack-plugin</code></li>
<li>配置：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// webpack.config.js</span><br><br><span class="hljs-comment">// 引入 html 插件</span><br><span class="hljs-keyword">const</span> HTMLWebpackPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;html-webpack-plugin&#x27;</span>);<br><br><span class="hljs-built_in">module</span>.exports = &#123;<br><span class="hljs-comment">/*</span><br><span class="hljs-comment">    其他配置参照基本使用，已省略</span><br><span class="hljs-comment">*/</span><br><br>  <span class="hljs-comment">// 配置 webpack 插件</span><br>  <span class="hljs-attr">plugins</span>: [<br>    <span class="hljs-keyword">new</span> HTMLWebpackPlugin(&#123;<br>       <span class="hljs-comment">// 自定义 html 标题</span><br>      <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;自定义title&quot;</span>,<br>      <span class="hljs-comment">// 指定 html 模板</span><br>      <span class="hljs-attr">template</span>: <span class="hljs-string">&quot;./src/index.html&quot;</span><br>    &#125;)<br>  ]<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="2-webpack-dev-server"><a href="#2-webpack-dev-server" class="headerlink" title="2. webpack-dev-server"></a>2. webpack-dev-server</h4><ul>
<li>作用：让项目在 webpack 内置服务器中运行，可根据项目改变自动刷新</li>
<li>安装：<code>npm i -D webpack-dev-server</code></li>
<li>配置：</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-comment">// package.json 的 scripts 配置项中添加 start 命令后，通过 npm run start 启动即可</span><br><br>&#123;<br>    <span class="hljs-attr">&quot;scripts&quot;</span>: &#123;<br>        <span class="hljs-attr">&quot;start&quot;</span>: <span class="hljs-string">&quot;webpack serve --open chrome.exe&quot;</span><br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="3-clean-webpack-plugin"><a href="#3-clean-webpack-plugin" class="headerlink" title="3. clean-webpack-plugin"></a>3. clean-webpack-plugin</h4><ul>
<li>作用：清除打包后的 dist 目录，保证打包后的文件为最新的。不使用该插件打包文件会进行替换，使用插件是先删除原文件再创建打包文件</li>
<li>安装：<code>npm i -D clean-webpack-plugin</code></li>
<li>配置：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// webpack.config.js</span><br><br><span class="hljs-comment">// 引入clean插件</span><br><span class="hljs-keyword">const</span> &#123; CleanWebpackPlugin &#125; = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;clean-webpack-plugin&#x27;</span>);<br><br><span class="hljs-built_in">module</span>.exports = &#123;<br>  <span class="hljs-attr">plugins</span>: [<br>    <span class="hljs-keyword">new</span> CleanWebpackPlugin()<br>  ]<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="4-设置引用模块"><a href="#4-设置引用模块" class="headerlink" title="4. 设置引用模块"></a>4. 设置引用模块</h4><ul>
<li>作用：设置 ts 文件可以作为模块使用</li>
<li>配置：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// webpack.config.js</span><br><br><span class="hljs-built_in">module</span>.exports = &#123;<br>   <span class="hljs-comment">// 设置引用模块</span><br>  <span class="hljs-attr">resolve</span>: &#123;<br>    <span class="hljs-comment">// 表示 ts, js 文件可以作为模块使用，不设置 ts 文件作为模块使用时会报错</span><br>    <span class="hljs-attr">extensions</span>: [<span class="hljs-string">&#x27;.ts&#x27;</span>, <span class="hljs-string">&#x27;.js&#x27;</span>]<br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="5-babel-解决兼容性问题"><a href="#5-babel-解决兼容性问题" class="headerlink" title="5. babel 解决兼容性问题"></a>5. babel 解决兼容性问题</h4><ul>
<li>作用：将采用 ECMAScript 2015+ 语法编写的代码转换为向后兼容的 JavaScript 语法，以便能够运行在当前和旧版本的浏览器或其他环境中</li>
<li>安装：<code>npm i -D @babel/core @babel/preset-env babel-loader core-js</code></li>
<li>配置：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// webpack.config.js</span><br><br><span class="hljs-built_in">module</span>.exports = &#123;<br>  <span class="hljs-attr">entry</span>: <span class="hljs-string">&quot;./src/index.ts&quot;</span>,<br>  <span class="hljs-attr">output</span>: &#123;<br>    <span class="hljs-attr">path</span>: path.resolve(__dirname, <span class="hljs-string">&#x27;dist&#x27;</span>),<br>    <span class="hljs-attr">filename</span>: <span class="hljs-string">&quot;bundle.js&quot;</span>,<br>    <br>    <span class="hljs-comment">// 告诉 webpack 不使用箭头函数。高版本 webpack 打包后的 js 中，包含 webpack 提供的箭头函数（非用户定义），不能兼容 ie</span><br>    <span class="hljs-attr">environment</span>: &#123;<br>      <span class="hljs-attr">arrowFunction</span>: <span class="hljs-literal">false</span>,<br>      <span class="hljs-attr">const</span>: <span class="hljs-literal">false</span><br>    &#125;<br>  &#125;,<br>  <span class="hljs-attr">module</span>: &#123;<br>    <span class="hljs-attr">rules</span>: [&#123;<br>      <span class="hljs-attr">test</span>: <span class="hljs-regexp">/\.ts$/</span>,<br>      <span class="hljs-comment">// 要使用的 loader，数组从后往前执行</span><br>      use: [<br>        <span class="hljs-comment">// 配合babel</span><br>        &#123;<br>          <span class="hljs-comment">// 指定加载器</span><br>          <span class="hljs-attr">loader</span>: <span class="hljs-string">&quot;babel-loader&quot;</span>,<br>          <span class="hljs-comment">// 设置babel</span><br>          <span class="hljs-attr">options</span>: &#123;<br>            <span class="hljs-comment">// 设置预定义的环境</span><br>            <span class="hljs-attr">presets</span>: [<br>              [<br>                <span class="hljs-comment">// 指定环境插件</span><br>                <span class="hljs-string">&quot;@babel/preset-env&quot;</span>,<br>                <span class="hljs-comment">// 配置信息</span><br>                &#123;<br>                  <span class="hljs-comment">// 指定兼容的浏览器版本</span><br>                  <span class="hljs-attr">targets</span>: &#123;<br>                    <span class="hljs-comment">// 兼容到 chrome 58 版本，和 ie 11 版本</span><br>                    <span class="hljs-string">&quot;chrome&quot;</span>: <span class="hljs-string">&quot;58&quot;</span>,<br>                    <span class="hljs-string">&quot;ie&quot;</span>: <span class="hljs-string">&quot;11&quot;</span><br>                  &#125;,<br>                  <span class="hljs-comment">// 指定 corejs 版本</span><br>                  <span class="hljs-string">&quot;corejs&quot;</span>: <span class="hljs-string">&quot;3&quot;</span>,<br>                  <span class="hljs-comment">// 使用 corejs 的方式，&quot;usage&quot;表示按需加载</span><br>                  <span class="hljs-string">&quot;useBuiltIns&quot;</span>: <span class="hljs-string">&quot;usage&quot;</span><br>                &#125;<br>              ]<br>            ]<br>          &#125;<br>        &#125;,<br>        <span class="hljs-string">&#x27;ts-loader&#x27;</span><br>      ],<br>      <span class="hljs-attr">exclude</span>: <span class="hljs-regexp">/node-modules/</span><br>    &#125;]<br>  &#125;,<br>  <span class="hljs-attr">plugins</span>: [<br>    <span class="hljs-keyword">new</span> HTMLWebpackPlugin(&#123;<br>      <span class="hljs-attr">template</span>: <span class="hljs-string">&quot;./src/index.html&quot;</span><br>    &#125;),<br>    <span class="hljs-keyword">new</span> CleanWebpackPlugin()<br>  ],<br>  <span class="hljs-attr">resolve</span>: &#123;<br>    <span class="hljs-attr">extensions</span>: [<span class="hljs-string">&#x27;.ts&#x27;</span>, <span class="hljs-string">&#x27;.js&#x27;</span>]<br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/ts/">ts</a>
                    
                  </div>
                
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/02/24/this%E6%8C%87%E5%90%91/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">this指向</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/02/24/ts%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/">
                        <span class="hidden-mobile">ts数据类型</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
